home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: HELP! File Pointers
- Date: 9 Jan 1996 12:25:54 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4cu8f2$c40@umbc9.umbc.edu>
- References: <4csr4c$fem@newsbf02.news.aol.com>
- NNTP-Posting-Host: f-umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Roberino <roberino@aol.com> wrote:
- |> I am currently trying to keep one file open while opening other
- |> files one at a time using a separate file pointer. However, as
- |> soon as I read a line from the second file, the first file pointer
- |> somehow gets destroyed and set to some position in the newly
- |> opened file. Has anyone else encountered this? And if so,
- |> is there a solution? (i.e. A way to protect the first file pointer
- |> from being overwritten.)
- |>
- |> Here are the steps I am performing:
- |>
- |> void main()
-
- Surely you mean 'int main (void)'...
-
- |> {
- |> FILE *File1;
- |> FILE *File2;
- |>
- |> File1 = fopen("FILENAME", "r+");
-
- Do you know that FILENAME was actually opened?
-
- |> /* loop through lines in File1 using fgets() */
- |>
- |> if (Condition) /* just indicating some condition was met */
- |> {
- |> File2 = fopen("FILENAME2", "r+");
-
- Do you know that FILENAME2 was actually opened?
-
- |> fgets(Line, File2); <----- As soon as this occurs, File1 gets
- |> wiped out. Why?
-
- Where is 'Line' declared? Also fgets() takes 3 parameters where you have given
- it only 2. In addition you never did an #include <stdio.h> to ensure proper
- prototypes for fgets() and fopen().
-
- Therefore your program should not have even compiled.
-
- |> }
-
-
- Don't forget 'return (0);'
-
- |> }
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-